﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EqRepair.Code.Classes;
using EqRepair.Code.Data;

namespace EqRepair.Web
{
	public partial class CompEQ : System.Web.UI.Page
	{
		private int EqId, OrgId;
		public EquipmentInOrganization eqH;

		protected void Page_Load(object sender, EventArgs e)
		{
			
		}

		protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
		{

		}

		

		protected void DetailsView1_ItemInserted1(object sender, DetailsViewInsertedEventArgs e)
		{
			using (var db = new DataClasses2DataContext())
			{
				db.SubmitChanges();
				GridView1.DataBind();
				AccessData.MoveSubAgregatToOrgEq(eqH);
				//db.EquipmentInOrganizations.Where()
				//string f = e.Values[0].ToString();
			}
		}

        protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            

        }

        protected void LinqDataSource4_Inserting(object sender, LinqDataSourceInsertEventArgs e)
        {
			eqH = (EquipmentInOrganization)e.NewObject;
			if (eqH.InstallDate == null || eqH.InstallDate==new DateTime(1,1,1,0,0,0))
				eqH.InstallDate = DateTime.Now;
			
			eqH.ParentID = 0;
			
        }

		protected void LinqDataSource4_Inserted(object sender, LinqDataSourceStatusEventArgs e)
		{
			
		}

		protected void LinqDataSource1_Deleting(object sender, LinqDataSourceDeleteEventArgs e)
		{
			EquipmentInOrganization eq = (EquipmentInOrganization)e.OriginalObject;
			AccessData.DelSubAgr(eq);
		}
	}
}
